<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Compilation Units</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Compilation Units' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">runtime</a></li><li><a href="index.html#2">Chapter 2: Emission</a></li><li><b>Compilation Units</b></li></ul></div>
<p class="purpose">The source text is divided into compilation units, and the material they lead to is similarly divided up.</p>

<ul class="toc"><li><a href="2-cu.html#SP1">&#167;1. Units</a></li><li><a href="2-cu.html#SP6">&#167;6. What unit a node belongs to</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Units.</b>The source text is divided up into "compilation units". Each extension is its
own compilation unit, and so is the main source text. This demarcation is also
reflected in the Inter hierarchy, where each different compilation unit has its
own sub-hierarchy, a <span class="extract"><span class="extract-syntax">module_request</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">module_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to_module</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">head_node</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">extension_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">extension</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::log</span><span class="plain-syntax">(</span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cu</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cu</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;null&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"unit'%W'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">cu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_node</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">module_request</span><span class="plain-syntax"> *</span><span class="function-syntax">CompilationUnits::to_module_package</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::to_module_package</span></span>:<br/>Hierarchy - <a href="2-hrr.html#SP18">&#167;18</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no unit"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">to_module</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure compilation_unit is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>The main source text, and the extensions included, are exactly the level-0
<span class="extract"><span class="extract-syntax">HEADING_NT</span></span> nodes in the parse tree which correspond to files read in, so we
can find them easily enough. This is done very early in compilation: see
<a href="../core-module/1-htc.html" class="internal">How To Compile (in core)</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::determine</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">SyntaxTree::traverse</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><a href="2-cu.html#SP2" class="function-link"><span class="function-syntax">CompilationUnits::look_for_cu</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::look_for_cu</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::get_type</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">) == </span><span class="identifier-syntax">HEADING_NT</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">h</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Headings::from_node</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">h</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">level</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">source_location</span><span class="plain-syntax"> </span><span class="identifier-syntax">sl</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::location</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sl</span><span class="plain-syntax">.</span><span class="identifier-syntax">file_of_origin</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-cu.html#SP2_1" class="named-paragraph-link"><span class="named-paragraph">Create a new compilation unit for this heading</span><span class="named-paragraph-number">2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2_1" class="paragraph-anchor"></a><b>&#167;2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Create a new compilation unit for this heading</span><span class="named-paragraph-number">2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ext</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Extensions::corresponding_to</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Lexer::file_of_origin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">))));</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">pname</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-cu.html#SP2_1_3" class="named-paragraph-link"><span class="named-paragraph">Compose a name for the unit package this will lead to</span><span class="named-paragraph-number">2.1.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">module_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">M</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::module_request</span><span class="plain-syntax">(</span><a href="2-emt.html#SP1" class="function-link"><span class="function-syntax">Emit::tree</span></a><span class="plain-syntax">(), </span><span class="identifier-syntax">pname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id_iname</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ext</span><span class="plain-syntax">) </span><span class="identifier-syntax">id_iname</span><span class="plain-syntax"> = </span><a href="2-hrr.html#SP12" class="function-link"><span class="function-syntax">Hierarchy::make_iname_in</span></a><span class="plain-syntax">(</span><span class="constant-syntax">EXTENSION_ID_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-cu.html#SP2_1_1" class="named-paragraph-link"><span class="named-paragraph">Give M a category</span><span class="named-paragraph-number">2.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">pname</span><span class="plain-syntax">)</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_node</span><span class="plain-syntax"> = </span><span class="identifier-syntax">p</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">to_module</span><span class="plain-syntax"> = </span><span class="identifier-syntax">M</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ext</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension_id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">id_iname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-cu.html#SP6" class="function-link"><span class="function-syntax">CompilationUnits::join</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ext</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-cu.html#SP2_1_2" class="named-paragraph-link"><span class="named-paragraph">Give M metadata indicating the source extension</span><span class="named-paragraph-number">2.1.2</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cu.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_1_1" class="paragraph-anchor"></a><b>&#167;2.1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Give M a category</span><span class="named-paragraph-number">2.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">cat</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ext</span><span class="plain-syntax">) </span><span class="identifier-syntax">cat</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Extensions::is_standard</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">)) </span><span class="identifier-syntax">cat</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_CATEGORY_MD_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">cat</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cu.html#SP2_1">&#167;2.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_1_2" class="paragraph-anchor"></a><b>&#167;2.1.2. </b>The extension credit consists of a single line, with name, version number
and author; together with any "extra credit" asked for by the extension.
</p>

<p class="commentary">For timing reasons, we need to schedule an agent to make this later: that
allows us to read sentences like "Use authorial modesty" between now and then.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Give M metadata indicating the source extension</span><span class="named-paragraph-number">2.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">desc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">desc</span><span class="plain-syntax">, </span><span class="string-syntax">"extension metadata for %S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">raw_title</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Sequence::queue</span><span class="plain-syntax">(&amp;</span><a href="2-cu.html#SP3" class="function-link"><span class="function-syntax">CompilationUnits::compilation_agent</span></a><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">STORE_POINTER_compilation_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">), </span><span class="identifier-syntax">desc</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cu.html#SP2_1">&#167;2.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::compilation_agent</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::compilation_agent</span></span>:<br/><a href="2-cu.html#SP2_1_2">&#167;2.1.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">CU</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_compilation_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ext</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CU</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">module_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">M</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CU</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">to_module</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_AUTHOR_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">raw_author_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_TITLE_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">raw_title</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">version</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">, </span><span class="string-syntax">"%v"</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_VERSION_MD_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">V</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="2-emt.html#SP6" class="function-link"><span class="function-syntax">Emit::numeric_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CU</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension_id</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">raw_title</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VersionNumbers::is_null</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="string-syntax">" version %v"</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="string-syntax">" by %S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">raw_author_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">extra_credit_as_lexed</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="string-syntax">" (%S)"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">extra_credit_as_lexed</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_CREDIT_MD_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">extra_credit_as_lexed</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_EXTRA_CREDIT_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">extra_credit_as_lexed</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">the_author_name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">the_author_name</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">author_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">self_penned</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">BibliographicData::story_author_is</span><span class="plain-syntax">(</span><span class="identifier-syntax">the_author_name</span><span class="plain-syntax">)) </span><span class="identifier-syntax">self_penned</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">modesty</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">authorial_modesty</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp;       </span><span class="comment-syntax"> if (1) extension doesn't ask to be modest</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Extensions::is_standard</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp; </span><span class="comment-syntax"> and (2) it's not e.g. the Standard Rules</span>
<span class="plain-syntax">        ((</span><span class="identifier-syntax">general_authorial_modesty</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||   </span><span class="comment-syntax"> and (3a) author doesn't ask to be modest, or</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">self_penned</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)))               </span><span class="comment-syntax">     (3b) didn't write this extension</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">modesty</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_MODESTY_MD_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">modesty</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">M</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_WORD_COUNT_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">TextFromFiles::total_word_count</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">read_into_file</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">the_author_name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2_1_3" class="paragraph-anchor"></a><b>&#167;2.1.3. </b>Here we must find a unique name, valid as an Inter identifier: the code
compiled from the compilation unit will go into a package of that name.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Compose a name for the unit package this will lead to</span><span class="named-paragraph-number">2.1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ext</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">pname</span><span class="plain-syntax">, </span><span class="string-syntax">"source_text"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">pname</span><span class="plain-syntax">, </span><span class="string-syntax">"%X"</span><span class="plain-syntax">, </span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">as_copy</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">work</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_THROUGH_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">pname</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::get</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">) == </span><span class="character-syntax">' '</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Str::put</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="character-syntax">'_'</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Str::put</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">Characters::tolower</span><span class="plain-syntax">(</span><span class="identifier-syntax">Str::get</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cu.html#SP2_1">&#167;2.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>For timing reasons, this second round of metadata &mdash; which provides
cross-references between the compilation unit modules, to show which ones
caused which other ones to be included &mdash; can only be written later. (It's
used only for indexing.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::complete_metadata</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ext</span><span class="plain-syntax"> = </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ext</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pack</span><span class="plain-syntax"> = </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">to_module</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">where_found</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_AT_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">body_text</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">inc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Extensions::get_inclusion_sentence</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">inc</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">                </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_INCLUDED_AT_MD_HL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    (</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">inc</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">source_location</span><span class="plain-syntax"> </span><span class="identifier-syntax">sl</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::location</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">inc</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sl</span><span class="plain-syntax">.</span><span class="identifier-syntax">file_of_origin</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Extensions::corresponding_to</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Lexer::file_of_origin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">inc</span><span class="plain-syntax">))));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner_id</span><span class="plain-syntax"> = </span><a href="2-cu.html#SP5" class="function-link"><span class="function-syntax">CompilationUnits::extension_id</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">owner_id</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_iname</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                            </span><span class="constant-syntax">EXT_INCLUDED_BY_MD_HL</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Lexer::word_location</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">inc</span><span class="plain-syntax">))).</span><span class="identifier-syntax">file_of_origin</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_AUTO_INCLUDED_MD_HL</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Extensions::is_standard</span><span class="plain-syntax">(</span><span class="identifier-syntax">ext</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><a href="2-hrr.html#SP23" class="function-link"><span class="function-syntax">Hierarchy::apply_metadata_from_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">, </span><span class="constant-syntax">EXT_STANDARD_MD_HL</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>This is in principle slow, and in practice fast, and anyway little used.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">CompilationUnits::extension_id</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::extension_id</span></span>:<br/><a href="2-cu.html#SP4">&#167;4</a><br/>Use Options - <a href="3-uo.html#SP1_3">&#167;1.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inform_extension</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner_C</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">owner_C</span><span class="plain-syntax">, </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">owner_C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension</span><span class="plain-syntax"> == </span><span class="identifier-syntax">owner</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">owner_C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extension_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. What unit a node belongs to.</b>We are going to need to determine, for any node <span class="extract"><span class="extract-syntax">p</span></span>, which compilation unit it
belongs to. If there were a fast way to go up in the syntax tree, that would be
easy &mdash; we could simply run upward until we reach a level-0 heading. But the
node links all run downwards. Instead, we'll annotate the nodes in a given unit.
The annotations propagates downwards thus:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::join</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::join</span></span>:<br/><a href="2-cu.html#SP2_1">&#167;2.1</a>, <a href="2-cu.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::get_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Node::set_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">d</span><span class="plain-syntax"> = </span><span class="identifier-syntax">p</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">; </span><span class="identifier-syntax">d</span><span class="plain-syntax">; </span><span class="identifier-syntax">d</span><span class="plain-syntax"> = </span><span class="identifier-syntax">d</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><a href="2-cu.html#SP6" class="function-link"><span class="function-syntax">CompilationUnits::join</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">d</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>Nodes are sometimes added later, so that it may be necessary to mark them
by hand as belonging to the same nodes as their progenitors:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompilationUnits::assign_to_same_unit</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::assign_to_same_unit</span></span>:<br/>Text Substitutions - <a href="4-ts.html#SP7_3">&#167;7.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cu.html#SP6" class="function-link"><span class="function-syntax">CompilationUnits::join</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="identifier-syntax">Node::get_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>As promised, then, given a parse node, we have to return its compilation unit:
but that's now easy.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">compilation_unit</span><span class="plain-syntax"> *</span><span class="function-syntax">CompilationUnits::find</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">CompilationUnits::find</span></span>:<br/>Hierarchy - <a href="2-hrr.html#SP19">&#167;19</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Node::get_unit</span><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-ni.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-rm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-hrr.html">hrr</a></li><li class="progresssection"><a href="2-ni.html">ni</a></li><li class="progresscurrent">cu</li><li class="progresssection"><a href="2-emt.html">emt</a></li><li class="progresssection"><a href="2-ec.html">ec</a></li><li class="progresssection"><a href="2-ea.html">ea</a></li><li class="progresssection"><a href="2-int.html">int</a></li><li class="progresssection"><a href="2-sv.html">sv</a></li><li class="progresssection"><a href="2-th.html">th</a></li><li class="progresssection"><a href="2-dv.html">dv</a></li><li class="progresssection"><a href="2-es.html">es</a></li><li class="progresssection"><a href="2-ic.html">ic</a></li><li class="progresssection"><a href="2-kd.html">kd</a></li><li class="progresssection"><a href="2-sc.html">sc</a></li><li class="progresssection"><a href="2-hnae.html">hnae</a></li><li class="progresssection"><a href="2-sn.html">sn</a></li><li class="progresssection"><a href="2-gpr.html">gpr</a></li><li class="progresssection"><a href="2-ie.html">ie</a></li><li class="progresschapter"><a href="3-gm.html">3</a></li><li class="progresschapter"><a href="4-enc.html">4</a></li><li class="progresschapter"><a href="5-act.html">5</a></li><li class="progresschapter"><a href="6-bd.html">6</a></li><li class="progresschapter"><a href="7-cg.html">7</a></li><li class="progressnext"><a href="2-emt.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

